﻿namespace ExamV5.OnlineExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.IO;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Wuqi.Webdiyer;

    public class FrmLookExamUser : Page
    {
        protected Button butExp;
        protected Button butQuery;
        protected GridView DataGridInfo;
        protected DropDownList DDLDept;
        protected DropDownList DDLOpertion;
        protected DropDownList DDLQuery;
        protected DropDownList DDLStatus;
        protected DropDownList DDLUPDept;
        protected HtmlForm Form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        protected Label labRescordCount;
        protected Label labTip;
        protected LinkButton LBDel;
        protected LinkButton LBEnd;
        protected LinkButton LBEnterExam;
        protected LinkButton LBFirstPage;
        protected LinkButton LBLastPage;
        protected LinkButton LBNextPage;
        protected LinkButton LBPrevPage;
        protected LinkButton LBPrint;
        protected LinkButton LBSelectPage;
        protected LinkButton LBSet;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        private string string_0 = "A";
        protected TextBox txtQuery;
        protected TextBox txtTime;
        protected UpdatePanel UPPart;

        protected AspNetPager aspPager;
        protected void butExp_Click(object sender, EventArgs e)
        {
            try
            {
                string cmdText = "";
                string key = Guid.NewGuid().ToString("N").ToUpper();
                string path = base.Server.MapPath("../") + @"\PublicFile\NoJoinExamUser" + key + ".csv";
                string str3 = "";
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                StreamWriter writer = new StreamWriter(path, true, Encoding.GetEncoding("GB2312"));
                writer.WriteLine("准考证号,考生姓名,所属部门,所属职务,所属岗位,考试名称,考试科目,登录IP,开考日期,开考时间,参考次数,考试状态");
                cmdText = "select d.DeptName,d.UPID,b.Worker,b.UserGWName,b.UserGWLevel,a.JoinExamNum,c.PaperStartTime,c.PaperEndTime,a.JoinDate,a.LastDate,c.ExamTime,a.ExamType,a.StartTime,a.LoginIP,b.UserName,a.UserCode,a.PaperID,a.ExamName,a.Subject,a.Flag as ExamStatus,Flag=case a.Flag when 'A' then '未参加考试' when 'B' then '正在考试'  when 'C' then '考试完成' when 'D' then '客观题批改完成' when 'E' then '考试批改完成' when 'G' then '异常操作' when 'Z' then '作弊标记' end from ExamUser a,UserInfo b,PaperInfo c,DeptInfo d where d.ID=b.DeptID and a.PaperID=c.ID and a.UserCode=b.UserCode ";
                if (this.DDLDept.SelectedItem.Value != "0")
                {
                    cmdText = cmdText + " and b.DeptID in (select b.ID from DeptInfo b where " + this.publicFun_0.GetManagDeptID(this.publicFun_0.CheckString(this.DDLDept.SelectedItem.Value)) + ")";
                }
                if (this.DDLStatus.SelectedItem.Value.Trim() == "C")
                {
                    cmdText = cmdText + " and (a.Flag='C' or a.Flag='D' or  a.Flag='E') and a.PaperID=" + this.int_0;
                }
                else if (!(this.DDLStatus.SelectedItem.Value.Trim() == "D"))
                {
                    cmdText = string.Concat(new object[] { cmdText, " and a.Flag='", this.DDLStatus.SelectedItem.Value.Trim(), "' and a.PaperID=", this.int_0 });
                }
                else
                {
                    cmdText = cmdText + " and a.PaperID=" + this.int_0;
                }
                if (this.txtQuery.Text.Trim() != "")
                {
                    cmdText = cmdText + " and " + this.publicFun_0.CheckString(this.DDLQuery.SelectedItem.Value) + " like '%" + this.publicFun_0.CheckString(this.txtQuery.Text) + "%'";
                }
                if (this.ViewState["ManagExam"].ToString() == "Y")
                {
                    cmdText = cmdText + " and c.ID<>0 ";
                }
                else if (this.ViewState["AddExam"].ToString() == "Y")
                {
                    cmdText = cmdText + " and c.InputUserCode='" + this.httpCookie_0.Value + "'";
                }
                else
                {
                    cmdText = cmdText + " and c.ID=0 ";
                }
                cmdText = cmdText + " order by " + this.ViewState["SortFiled"].ToString() + this.ViewState["SortType"].ToString();
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                connection.Open();
                SqlCommand command = new SqlCommand(cmdText, connection);
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    str3 = "";
                    str3 = (str3 + reader["UserCode"].ToString().Trim() + "\x00b7,") + reader["UserName"].ToString().Trim() + ",";
                    if (!(reader["UPID"].ToString().Trim() == "0"))
                    {
                        str3 = str3 + this.publicFun_0.GetValues("select DeptName from DeptInfo where ID=" + reader["UPID"].ToString().Trim(), "DeptName") + @"\" + reader["DeptName"].ToString().Trim() + ",";
                    }
                    else
                    {
                        str3 = str3 + reader["DeptName"].ToString().Trim() + ",";
                    }
                    str3 = ((((((((str3 + reader["Worker"].ToString().Trim() + ",") + reader["UserGWName"].ToString().Trim() + ",") + reader["ExamName"].ToString().Trim() + ",") + reader["Subject"].ToString().Trim() + ",") + reader["LoginIP"].ToString().Trim() + ",") + reader["JoinDate"].ToString().Trim() + ",") + reader["StartTime"].ToString().Trim() + ",") + reader["JoinExamNum"].ToString().Trim() + ",") + reader["Flag"].ToString().Trim() + ",";
                    writer.WriteLine(str3);
                }
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
                writer.Flush();
                writer.Close();
                this.labTip.Text = " 导出成功！单击【<a href='../FrmDownLoad.aspx?FileName=NoJoinExamUser" + key + ".csv' target=_blank><font color=red>下载</font></a>】进行保存";
            }
            catch
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BExpErrTip", @"alert('导出数据失败！\n\n请将PublicFile目录设置为Everyone用户可修改权限！')", true);
            }
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void butQuery_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.aspPager.CurrentPageIndex = 1;
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DataGridInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.DataGridInfo.PageIndex = e.NewPageIndex;
            this.method_0();
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.DataItemIndex == -1)
            //{
            //    this.DataGridInfo.Attributes.Add("oldValue", "#FFFFFF");
            //    this.DataGridInfo.Attributes.Add("singleValue", "#FFFFFF");
            //}
            //else
            //{
            //    e.Row.Attributes.Add("onmouseover", "this.bgColor='#F6F5F5'");
            //    if ((e.Row.DataItemIndex % 2) != 0)
            //    {
            //        e.Row.Attributes.Add("bgcolor", "#FFFFFF");
            //        e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('oldValue')");
            //    }
            //    else
            //    {
            //        e.Row.Attributes.Add("bgcolor", "#FFFFFF");
            //        e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('singleValue')");
            //    }
            //}
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[3].Text.Length > Convert.ToInt32(this.ViewState["SubStrLen"].ToString()))
                {
                    e.Row.Cells[3].Text = "<a title=" + e.Row.Cells[3].Text + ">" + e.Row.Cells[3].Text.Substring(0, Convert.ToInt32(this.ViewState["SubStrLen"].ToString())) + "…</a>";
                }
                if (e.Row.Cells[8].Text.Trim().IndexOf("正考") > -1)
                {
                    DateTime time3;
                    TimeSpan span;
                    string str2 = this.DataGridInfo.DataKeys[e.Row.RowIndex]["JoinDate"].ToString();
                    if (str2.Trim() != "")
                    {
                        if (!(Convert.ToDateTime(str2.Trim()).ToShortDateString() != DateTime.Now.ToShortDateString()))
                        {
                            time3 = Convert.ToDateTime(e.Row.Cells[6].Text.Trim());
                            span = (TimeSpan) (Convert.ToDateTime(DateTime.Now.ToShortTimeString()) - time3);
                            if (span.TotalMinutes > Convert.ToInt32(this.DataGridInfo.DataKeys[e.Row.RowIndex]["ExamTime"].ToString()))
                            {
                                e.Row.Cells[8].Text = "异常退出考场";
                            }
                        }
                        else
                        {
                            e.Row.Cells[8].Text = "异常退出考场";
                        }
                    }
                    else
                    {
                        time3 = Convert.ToDateTime(e.Row.Cells[6].Text.Trim());
                        span = (TimeSpan) (Convert.ToDateTime(DateTime.Now.ToShortTimeString()) - time3);
                        if (span.TotalMinutes > Convert.ToInt32(this.DataGridInfo.DataKeys[e.Row.RowIndex]["ExamTime"].ToString()))
                        {
                            e.Row.Cells[8].Text = "异常退出考场";
                        }
                    }
                }
                if (e.Row.Cells[8].Text.Trim() == "未考")
                {
                    DateTime time2 = Convert.ToDateTime(this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperStartTime"].ToString());
                    DateTime time = Convert.ToDateTime(this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperEndTime"].ToString());
                    if (DateTime.Now < time2)
                    {
                        e.Row.Cells[8].Text = "未考(<font color=red>未到</font>)";
                    }
                    if (DateTime.Now > time)
                    {
                        e.Row.Cells[8].Text = "未考(<font color=red>过期</font>)";
                    }
                }
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                if (this.ViewState["SortType"].ToString() != " Desc")
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "UserCode":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "UserName":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "ExamName":
                            e.Row.Cells[3].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "LoginIP":
                            e.Row.Cells[4].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "JoinDate":
                            e.Row.Cells[5].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "StartTime":
                            e.Row.Cells[6].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "JoinExamNum":
                            e.Row.Cells[7].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "Flag":
                            e.Row.Cells[8].Controls.Add(new LiteralControl("↓"));
                            return;
                    }
                    e.Row.Cells[1].Controls.Add(new LiteralControl("↓"));
                }
                else
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "UserCode":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "UserName":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "ExamName":
                            e.Row.Cells[3].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "LoginIP":
                            e.Row.Cells[4].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "JoinDate":
                            e.Row.Cells[5].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "StartTime":
                            e.Row.Cells[6].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "JoinExamNum":
                            e.Row.Cells[7].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "Flag":
                            e.Row.Cells[8].Controls.Add(new LiteralControl("↑"));
                            return;
                    }
                    e.Row.Cells[1].Controls.Add(new LiteralControl("↑"));
                }
            }
        }

        protected void DataGridInfo_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sortExpression = e.SortExpression;
            if (!(this.ViewState["SortFiled"].ToString() == sortExpression))
            {
                this.ViewState["SortFiled"] = e.SortExpression;
            }
            else if (!(this.ViewState["SortType"].ToString() == " Desc"))
            {
                this.ViewState["SortType"] = " Desc";
            }
            else
            {
                this.ViewState["SortType"] = " ASC";
            }
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DataGridInfo_PreRender(object sender, EventArgs e)
        {
            // 使用<TH>替换<TD> 
            this.DataGridInfo.UseAccessibleHeader = true;
            //HeaderRow将被<thead>包裹，数据行将被<tbody>包裹
            this.DataGridInfo.HeaderRow.TableSection = TableRowSection.TableHeader;
        }

        protected void aspPager_PageChanged(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = this.aspPager.CurrentPageIndex - 1;
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DDLDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DDLStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DDLUPDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DDLDept.Items.Clear();
            this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
            if (this.DDLDept.Items.Count == 0)
            {
                if (!(this.DDLUPDept.SelectedItem.Value == "0"))
                {
                    ListItem item = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                    this.DDLDept.Items.Add(item);
                }
                else
                {
                    ListItem item2 = new ListItem("--所有部门--", "0");
                    this.DDLDept.Items.Insert(0, item2);
                }
            }
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void LBDel_Click(object sender, EventArgs e)
        {
            int num = 0;
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = null;
            string cmdText = "";
            for (int i = 0; i < this.DataGridInfo.Rows.Count; i++)
            {
                CheckBox box = (CheckBox) this.DataGridInfo.Rows[i].FindControl("CheckBoxSelect");
                if (box.Checked)
                {
                    if (this.DataGridInfo.Rows[i].Cells[8].Text.Trim().IndexOf("未考") != -1)
                    {
                        cmdText = "delete from ExamUser where UserCode='" + this.DataGridInfo.Rows[i].Cells[1].Text.Trim() + "' and PaperID=" + this.DataGridInfo.DataKeys[i]["PaperID"].ToString();
                        cmdText = cmdText + ";delete from PaperData where UserCode='" + this.DataGridInfo.Rows[i].Cells[1].Text.Trim() + "' and PaperID=" + this.DataGridInfo.DataKeys[i]["PaperID"].ToString();
                        cmdText = cmdText + ";delete from CheckPaper where UserCode='" + this.DataGridInfo.Rows[i].Cells[1].Text.Trim() + "' and PaperID=" + this.DataGridInfo.DataKeys[i]["PaperID"].ToString();
                        cmdText = cmdText + ";delete from Systip where GetNumber='" + this.DataGridInfo.Rows[i].Cells[1].Text.Trim() + "' and Formtable='PaperInfo' and FormID=" + this.DataGridInfo.DataKeys[i]["PaperID"].ToString();
                        cmdText = cmdText + ";insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('删除[" + this.DataGridInfo.Rows[i].Cells[1].Text.Trim() + "]考生考试记录！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')";
                    }
                    if (cmdText.Trim() != "")
                    {
                        command = new SqlCommand(cmdText, connection);
                        command.ExecuteNonQuery();
                        command.Dispose();
                        num = 1;
                    }
                }
            }
            connection.Close();
            connection.Dispose();
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
            this.LBSelectPage.Text = "选中当页";
            if (num <= 0)
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BDelExam", "alert('没有找到符合条件的数据，操作失败！')", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BDelExam", "alert('删除考试人员操作成功！')", true);
            }
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void LBEnd_Click(object sender, EventArgs e)
        {
            int num = 0;
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = null;
            string cmdText = "";
            for (int i = 0; i < this.DataGridInfo.Rows.Count; i++)
            {
                CheckBox box = (CheckBox) this.DataGridInfo.Rows[i].FindControl("CheckBoxSelect");
                if (box.Checked)
                {
                    if (((this.DataGridInfo.DataKeys[i]["ExamStatus"].ToString() == "E") || (this.DataGridInfo.DataKeys[i]["ExamStatus"].ToString() == "D")) || (this.DataGridInfo.DataKeys[i]["ExamStatus"].ToString() == "C"))
                    {
                        cmdText = "update ExamUser set Flag='Z' where UserCode='" + this.DataGridInfo.Rows[i].Cells[1].Text.Trim() + "' and PaperID=" + this.DataGridInfo.DataKeys[i]["PaperID"].ToString();
                        cmdText = cmdText + ";insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('设置[" + this.DataGridInfo.Rows[i].Cells[1].Text.Trim() + "]考生考试作弊标记！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')";
                    }
                    if (cmdText.Trim() != "")
                    {
                        command = new SqlCommand(cmdText, connection);
                        command.ExecuteNonQuery();
                        command.Dispose();
                        num = 1;
                    }
                }
            }
            connection.Close();
            connection.Dispose();
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
            this.LBSelectPage.Text = "选中当页";
            if (num <= 0)
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BDelExamAB", "alert('没有找到符合条件的数据，操作失败！')", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BDelExamAB", "alert('设置考生作弊标记操作成功！')", true);
            }
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void LBEnterExam_Click(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand("select a.LastDate,b.ExamTime,a.UserCode,a.PaperID,a.StartTime,a.ExamName,a.JoinDate from ExamUser a,PaperInfo b where b.ID=a.PaperID and a.ExamType='A' and a.Flag='B'", connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                DateTime time;
                TimeSpan span;
                string str2 = reader["JoinDate"].ToString().Replace("&nbsp;", "");
                if (!(str2.Trim() != ""))
                {
                    time = Convert.ToDateTime(reader["StartTime"]);
                    span = (TimeSpan) (Convert.ToDateTime(DateTime.Now.ToShortTimeString()) - time);
                    if (span.TotalMinutes > Convert.ToInt32(reader["ExamTime"]))
                    {
                        this.method_1(reader["PaperID"].ToString(), reader["UserCode"].ToString(), reader["ExamName"].ToString());
                    }
                }
                else
                {
                    if (Convert.ToDateTime(str2.Trim()).ToShortDateString() != DateTime.Now.ToShortDateString())
                    {
                        this.method_1(reader["PaperID"].ToString(), reader["UserCode"].ToString(), reader["ExamName"].ToString());
                        continue;
                    }
                    time = Convert.ToDateTime(reader["StartTime"]);
                    span = (TimeSpan) (Convert.ToDateTime(DateTime.Now.ToShortTimeString()) - time);
                    if (span.TotalMinutes > Convert.ToInt32(reader["ExamTime"]))
                    {
                        this.method_1(reader["PaperID"].ToString(), reader["UserCode"].ToString(), reader["ExamName"].ToString());
                    }
                }
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BEnterExam", "alert('异常退出考场，统一结算成功！')", true);
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void LBFirstPage_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void LBLastPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageCount > 0)
            {
                this.DataGridInfo.PageIndex = this.DataGridInfo.PageCount - 1;
                this.method_0();
            }
        }

        protected void LBNextPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex < (this.DataGridInfo.PageCount - 1))
            {
                this.DataGridInfo.PageIndex++;
                this.method_0();
            }
        }

        protected void LBPrevPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex > 0)
            {
                this.DataGridInfo.PageIndex--;
                this.method_0();
            }
        }

        protected void LBPrint_Click(object sender, EventArgs e)
        {
            string str = "";
            for (int i = 0; i < this.DataGridInfo.Rows.Count; i++)
            {
                CheckBox box = (CheckBox) this.DataGridInfo.Rows[i].FindControl("CheckBoxSelect");
                if (box.Checked)
                {
                    str = str + base.Server.UrlEncode(this.DataGridInfo.Rows[i].Cells[1].Text) + "|";
                }
            }
            if (str.Trim() == "")
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('请选中需要打印的考生名单！')", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "PrintData", string.Concat(new object[] { "PrintInfo('", this.int_0, "','", str, "');" }), true);
            }
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void LBSelectPage_Click(object sender, EventArgs e)
        {
            int num;
            CheckBox box;
            if (this.LBSelectPage.Text == "选中当页")
            {
                for (num = 0; num < this.DataGridInfo.Rows.Count; num++)
                {
                    box = (CheckBox) this.DataGridInfo.Rows[num].FindControl("CheckBoxSelect");
                    if (box.Enabled)
                    {
                        box.Checked = true;
                    }
                }
                this.LBSelectPage.Text = "取消所选";
            }
            else
            {
                for (num = 0; num < this.DataGridInfo.Rows.Count; num++)
                {
                    box = (CheckBox) this.DataGridInfo.Rows[num].FindControl("CheckBoxSelect");
                    box.Checked = false;
                }
                this.LBSelectPage.Text = "选中当页";
            }
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void LBSet_Click(object sender, EventArgs e)
        {
            bool flag = false;
            int num = 0;
            string str = "+";
            try
            {
                num = Convert.ToInt16(this.txtTime.Text.Trim());
            }
            catch
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTime", "alert('设置延长或缩短时间值不合法！')", true);
            }
            if (!(this.DDLOpertion.SelectedItem.Value == "A"))
            {
                str = "-";
            }
            else
            {
                str = "+";
            }
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = null;
            string str2 = "";
            for (int i = 0; i < this.DataGridInfo.Rows.Count; i++)
            {
                int num3 = Convert.ToInt16(this.DataGridInfo.DataKeys[i]["PaperJoinNum"].ToString());
                int num4 = Convert.ToInt16(this.DataGridInfo.Rows[i].Cells[7].Text.Trim());
                CheckBox box = (CheckBox) this.DataGridInfo.Rows[i].FindControl("CheckBoxSelect");
                if (box.Checked)
                {
                    if ((this.DataGridInfo.DataKeys[i]["ExamStatus"].ToString() != "B") ? !(this.DataGridInfo.DataKeys[i]["ExamStatus"].ToString() != "G") : true)
                    {
                        str2 = string.Concat(new object[] { "update ExamUser set LastTime=LastTime", str, num, ",Flag='A' where UserCode='", this.DataGridInfo.Rows[i].Cells[1].Text.Trim(), "' and PaperID=", this.DataGridInfo.DataKeys[i]["PaperID"].ToString() });
                        command = new SqlCommand(str2 + ";insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('设置[" + this.DataGridInfo.Rows[i].Cells[1].Text.Trim() + "]考生重考！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')", connection);
                        command.ExecuteNonQuery();
                        command.Dispose();
                    }
                    else if (!(((num3 == 0) || (num4 >= num3)) ? (num3 != 0) : false))
                    {
                        str2 = string.Concat(new object[] { "update ExamUser set LastTime=", this.DataGridInfo.DataKeys[i]["ExamTime"].ToString(), str, num, ",Flag='A',IsSave=0,StartTime='',JoinDate='',LastDate='',EndTime='',GetOldCountFen=0,GetCountFen=0,LoginIP='' where UserCode='", this.DataGridInfo.Rows[i].Cells[1].Text.Trim(), "' and PaperID=", this.DataGridInfo.DataKeys[i]["PaperID"].ToString(), ";delete from CheckPaper where  UserCode='", this.DataGridInfo.Rows[i].Cells[1].Text.Trim(), "' and PaperID=", this.DataGridInfo.DataKeys[i]["PaperID"].ToString() });
                        command = new SqlCommand(str2 + ";insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('设置[" + this.DataGridInfo.Rows[i].Cells[1].Text.Trim() + "]考生重考！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')", connection);
                        command.ExecuteNonQuery();
                        command.Dispose();
                    }
                    else
                    {
                        flag = true;
                    }
                }
            }
            connection.Close();
            connection.Dispose();
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
            this.LBSelectPage.Text = "选中当页";
            if (flag)
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BReExam", "alert('有些考生重考次数已达上限无法重考！其它设置重考操作成功！')", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BReExam", "alert('设置重考操作成功！')", true);
            }
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        private void method_0()
        {
            string selectCommandText = "";
            selectCommandText = "select c.JoinExamNum as PaperJoinNum,a.JoinExamNum,c.PaperStartTime,c.PaperEndTime,a.JoinDate,a.LastDate,c.ExamTime,a.ExamType,a.StartTime,a.LoginIP,b.UserName,a.UserCode,a.PaperID,a.ExamName,a.Subject,a.Flag as ExamStatus,Flag=case a.Flag when 'A' then '未考' when 'B' then '正考'  when 'C' then '考完' when 'D' then '客观题批完' when 'E' then '批改完成' when 'G' then '异常操作' when 'Z' then '作弊标记' end from ExamUser a,UserInfo b,PaperInfo c  where a.PaperID=c.ID and a.UserCode=b.UserCode ";
            if (this.DDLDept.SelectedItem.Value != "0")
            {
                selectCommandText = selectCommandText + " and b.DeptID in (select b.ID from DeptInfo b where " + this.publicFun_0.GetManagDeptID(this.publicFun_0.CheckString(this.DDLDept.SelectedItem.Value)) + ")";
            }
            if (this.DDLStatus.SelectedItem.Value.Trim() != "C")
            {
                if (!(this.DDLStatus.SelectedItem.Value.Trim() == "D"))
                {
                    selectCommandText = string.Concat(new object[] { selectCommandText, " and a.Flag='", this.DDLStatus.SelectedItem.Value.Trim(), "' and a.PaperID=", this.int_0 });
                }
                else
                {
                    selectCommandText = selectCommandText + " and a.PaperID=" + this.int_0;
                }
            }
            else
            {
                selectCommandText = selectCommandText + " and (a.Flag='C' or a.Flag='D' or  a.Flag='E') and a.PaperID=" + this.int_0;
            }
            if (this.txtQuery.Text.Trim() != "")
            {
                selectCommandText = selectCommandText + " and " + this.publicFun_0.CheckString(this.DDLQuery.SelectedItem.Value) + " like '%" + this.publicFun_0.CheckString(this.txtQuery.Text) + "%'";
            }
            if (this.ViewState["ManagExam"].ToString() != "Y")
            {
                if (!(this.ViewState["AddExam"].ToString() == "Y"))
                {
                    selectCommandText = selectCommandText + " and c.ID=0 ";
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BPower", "alert('考试监考权限未开放！')", true);
                }
                else
                {
                    selectCommandText = selectCommandText + " and c.InputUserCode='" + this.httpCookie_0.Value + "'";
                }
            }
            else
            {
                selectCommandText = selectCommandText + " and c.ID<>0 ";
            }
            selectCommandText = selectCommandText + " order by " + this.ViewState["SortFiled"].ToString() + this.ViewState["SortType"].ToString();
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "DataInfo");
            this.DataGridInfo.DataSource = dataSet.Tables["DataInfo"].DefaultView;
            this.DataGridInfo.DataBind();
            //this.labRescordCount.Text = "总共&nbsp;<font color='#0000C0'><b>" + dataSet.Tables["DataInfo"].Rows.Count.ToString() + "</b></font>&nbsp;条记录&nbsp;<font color='#0000C0'><b>" + Convert.ToString((int) (this.DataGridInfo.PageIndex + 1)) + "/" + this.DataGridInfo.PageCount.ToString() + "</b></font>&nbsp;页&nbsp;";
            this.labRescordCount.Text = "总共&nbsp;<i>" + dataSet.Tables["DataInfo"].Rows.Count.ToString() + "</i>&nbsp;条记录&nbsp;<b>" + Convert.ToString((int)(this.DataGridInfo.PageIndex + 1)) + "/" + this.DataGridInfo.PageCount.ToString() + "</b>&nbsp;页&nbsp;";
            this.aspPager.RecordCount = dataSet.Tables["DataInfo"].Rows.Count;
            adapter.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
        }

        private void method_1(string string_1, string string_2, string string_3)
        {
            string str = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();
            string str2 = "E";
            double num2 = 0.0;
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand("select RubricSFen,RubricDFen,RubricBFen,RubricFFen,RubricAFen,RubricCFen,RubricTFen,RubricANFen,RubricOFen,RubricJFen from CheckPaper where UserCode='" + string_2 + "' and PaperID='" + string_1 + "'", connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                int num4;
                if (((((reader["RubricAFen"].ToString().Trim() != "") || (reader["RubricCFen"].ToString().Trim() != "")) || ((reader["RubricTFen"].ToString().Trim() != "") || (reader["RubricANFen"].ToString().Trim() != ""))) || ((reader["RubricOFen"].ToString().Trim() != "") || (reader["RubricJFen"].ToString().Trim() != ""))) || (reader["RubricFFen"].ToString().Trim() != ""))
                {
                    str2 = "D";
                }
                else
                {
                    str2 = "E";
                }
                if (reader["RubricSFen"].ToString().Trim() != "")
                {
                    string[] strArray11 = reader["RubricSFen"].ToString().Trim().Split(new char[] { '|' });
                    for (num4 = 0; num4 < strArray11.Length; num4++)
                    {
                        if (strArray11[num4].Trim() != "")
                        {
                            num2 += Convert.ToDouble(strArray11[num4].Trim());
                        }
                    }
                }
                if (reader["RubricDFen"].ToString().Trim() != "")
                {
                    string[] strArray10 = reader["RubricDFen"].ToString().Trim().Split(new char[] { '|' });
                    for (num4 = 0; num4 < strArray10.Length; num4++)
                    {
                        if (strArray10[num4].Trim() != "")
                        {
                            num2 += Convert.ToDouble(strArray10[num4].Trim());
                        }
                    }
                }
                if (reader["RubricBFen"].ToString().Trim() != "")
                {
                    string[] strArray9 = reader["RubricBFen"].ToString().Trim().Split(new char[] { '|' });
                    for (num4 = 0; num4 < strArray9.Length; num4++)
                    {
                        if (strArray9[num4].Trim() != "")
                        {
                            num2 += Convert.ToDouble(strArray9[num4].Trim());
                        }
                    }
                }
                if (reader["RubricFFen"].ToString().Trim() != "")
                {
                    string[] strArray8 = reader["RubricFFen"].ToString().Trim().Split(new char[] { '|' });
                    for (num4 = 0; num4 < strArray8.Length; num4++)
                    {
                        if (strArray8[num4].Trim() != "")
                        {
                            num2 += Convert.ToDouble(strArray8[num4].Trim());
                        }
                    }
                }
                if (reader["RubricAFen"].ToString().Trim() != "")
                {
                    string[] strArray7 = reader["RubricAFen"].ToString().Trim().Split(new char[] { '|' });
                    for (num4 = 0; num4 < strArray7.Length; num4++)
                    {
                        if (strArray7[num4].Trim() != "")
                        {
                            num2 += Convert.ToDouble(strArray7[num4].Trim());
                        }
                    }
                }
                if (reader["RubricCFen"].ToString().Trim() != "")
                {
                    string[] strArray6 = reader["RubricCFen"].ToString().Trim().Split(new char[] { '|' });
                    for (num4 = 0; num4 < strArray6.Length; num4++)
                    {
                        if (strArray6[num4].Trim() != "")
                        {
                            num2 += Convert.ToDouble(strArray6[num4].Trim());
                        }
                    }
                }
                if (reader["RubricANFen"].ToString().Trim() != "")
                {
                    string[] strArray5 = reader["RubricANFen"].ToString().Trim().Split(new char[] { '|' });
                    for (num4 = 0; num4 < strArray5.Length; num4++)
                    {
                        if (strArray5[num4].Trim() != "")
                        {
                            num2 += Convert.ToDouble(strArray5[num4].Trim());
                        }
                    }
                }
                if (reader["RubricTFen"].ToString().Trim() != "")
                {
                    string[] strArray4 = reader["RubricTFen"].ToString().Trim().Split(new char[] { '|' });
                    for (num4 = 0; num4 < strArray4.Length; num4++)
                    {
                        if (strArray4[num4].Trim() != "")
                        {
                            num2 += Convert.ToDouble(strArray4[num4].Trim());
                        }
                    }
                }
                if (reader["RubricOFen"].ToString().Trim() != "")
                {
                    string[] strArray3 = reader["RubricOFen"].ToString().Trim().Split(new char[] { '|' });
                    for (num4 = 0; num4 < strArray3.Length; num4++)
                    {
                        if (strArray3[num4].Trim() != "")
                        {
                            num2 += Convert.ToDouble(strArray3[num4].Trim());
                        }
                    }
                }
                if (reader["RubricJFen"].ToString().Trim() != "")
                {
                    string[] strArray2 = reader["RubricJFen"].ToString().Trim().Split(new char[] { '|' });
                    for (num4 = 0; num4 < strArray2.Length; num4++)
                    {
                        if (strArray2[num4].Trim() != "")
                        {
                            num2 += Convert.ToDouble(strArray2[num4].Trim());
                        }
                    }
                }
                this.publicFun_0.ExecuteSql(string.Concat(new object[] { 
                    "update ExamUser set GetOldCountFen=", num2, ",GetCountFen=", num2, ",Flag='", str2, "',EndTime='", str, "',LastDate='", DateTime.Now.ToShortDateString(), "' where UserCode='", string_2, "' and PaperID='", string_1, "';insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('强行给[", string_2, 
                    "]考生交卷[", string_3, "]！','", this.httpCookie_1.Value, "','", this.httpCookie_0.Value, "')"
                 }));
            }
            else
            {
                this.publicFun_0.ExecuteSql("update ExamUser set GetOldCountFen=0,GetCountFen=0,Flag='E',EndTime='" + str + "',LastDate='" + DateTime.Now.ToShortDateString() + "' where UserCode='" + string_2 + "' and PaperID='" + string_1 + "';insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('强行给[" + string_2 + "]考生交卷[" + string_3 + "]！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            double num3 = 0.0;
            string values = this.publicFun_0.GetValues(string.Concat(new object[] { "select StudyFen from GradeReule where PaperID=", string_1, " and (", num2, ">=MinValue  and ", num2, "<=MaxValue)" }), "StudyFen");
            if (values.Trim() == "")
            {
                values = "0";
            }
            num3 = Convert.ToDouble(values);
            this.publicFun_0.ExecuteSql(string.Concat(new object[] { "delete  UserStudyFen where UserCode='", this.httpCookie_0.Value, "' and ExamOrStudy='E' and Formtable='PaperInfo' and FormID=", string_1, ";insert into UserStudyFen(UserCode,ExamStudyName,StudyFen,Formtable,FormID,ExamOrStudy) values('", this.httpCookie_0.Value, "','", string_3, "','", num3, "','PaperInfo','", string_1, "','E')" }));
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            this.int_0 = Convert.ToInt32(base.Request["PaperID"].ToString());
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Expires = 0;
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() != "Yes")
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                    }
                    else
                    {
                        this.string_0 = base.Request["Flag"].ToString().Trim();
                        this.DDLStatus.Items.FindByValue(this.string_0.Trim()).Selected = true;
                        this.txtQuery.Attributes.Add("onkeydown", "SubmitKeyClick('butQuery');");
                        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                        connection.Open();
                        SqlCommand command = new SqlCommand("select AddExam,ManagExam  from UserPower where UserCode='" + this.httpCookie_0.Value + "'", connection);
                        SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            this.ViewState["AddExam"] = reader["AddExam"].ToString();
                            this.ViewState["ManagExam"] = reader["ManagExam"].ToString();
                        }
                        reader.Close();
                        command.Dispose();
                        connection.Close();
                        connection.Dispose();
                        this.ViewState["SortFiled"] = "UserCode";
                        this.ViewState["SortType"] = " Desc";
                        this.DDLUPDept.DataTextField = "DeptName";
                        this.DDLUPDept.DataValueField = "ID";
                        if (!(this.httpCookie_2.Value == "C"))
                        {
                            this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where ID=" + this.httpCookie_3.Value + " order by SortInfo,ID");
                        }
                        else
                        {
                            this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where UPID=0  order by SortInfo,ID");
                        }
                        this.DDLUPDept.DataBind();
                        if (this.httpCookie_2.Value == "C")
                        {
                            this.DDLUPDept.SelectedIndex = -1;
                            this.DDLDept.SelectedIndex = -1;
                            ListItem item2 = new ListItem("--所有单位--", "0");
                            ListItem item3 = new ListItem("--所有部门--", "0");
                            this.DDLDept.Items.Insert(0, item3);
                            this.DDLUPDept.Items.Insert(0, item2);
                        }
                        else
                        {
                            this.DDLDept.Items.Clear();
                            this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
                            if (this.DDLDept.Items.Count == 0)
                            {
                                ListItem item = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                                this.DDLDept.Items.Add(item);
                            }
                        }
                        this.LBSet.Attributes.Add("onclick", @"javascript:{if(confirm('考试完成设置重考将清除考试成绩和作答记录。\n\n断电死机非法退出设置重考可继考。\n\n请再次确定将所有选中考生设置重考吗？')==false) return false;}");
                        this.LBDel.Attributes.Add("onclick", @"javascript:{if(confirm('此操作只能删除未参加考试人员。\n\n删除后相应考生将无法参加本次考试。\n\n请再次确定删除所有选中考生信息吗？')==false) return false;}");
                        this.LBEnd.Attributes.Add("onclick", @"javascript:{if(confirm('作弊标记只能设置已交卷人员。\n\n设置作弊标记后交无法修改。\n\n请再次确定要设置作弊标记所有选中的考生吗？')==false) return false;}");
                        string str = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='SubStrLength'", "ParmValue").Trim();
                        if (str.Trim() == "")
                        {
                            str = "20";
                        }
                        this.ViewState["SubStrLen"] = str;
                        this.method_0();
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

